def smp_numb(x):
    return all(x%k != 0 for k in range(2, int(x**(0.5))+1))

def spr():
    list_of_nums = []
    for i in range(101, 998):
        if smp_numb(i):
            list_of_nums.append(i)
    return list_of_nums

slov = {
    'zero':'0',
    'one':'1',
    'two':'2',
    'three':'3',
    'four':'4',
    'five':'5',
    'six':'6',
    'seven':'7',
    'eight':'8',
    'nine':'9',
    }

word = input()

sl = word.split()

h = ''

for m in sl:
    h += slov[m]

if len(h) != 3:
    print("Wrong input")

else:
    a = max(x for x in spr() if x <= int(h))
    b = min(x for x in spr() if x >= int(h))
    if abs(int(h)-a) > abs(int(h)-b):
        print(b)

    else:
        print(a)
